﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using WP09S03_OfficeTracking.DAL;
using WP09S03_OfficeTracking.DAL.DSItemTableAdapters;


namespace WP09S03_OfficeTracking.UserControls
{

    public partial class CtrlItem : UserControl
    {
        private vw_ItemAndItemDetailTableAdapter adpItem;
        private CategoryTableAdapter adpCate;        

        private int consumable = 0;
        private int statusID = 0;
        public int Consumable
        {
            get { return consumable; }
            set { consumable = value; }
        }

        public int StatusID
        {
            get { return statusID; }
            set { statusID = value; }
        }

        public CtrlItem()
        {
            InitializeComponent();
            adpItem = new vw_ItemAndItemDetailTableAdapter();
            adpCate = new CategoryTableAdapter();
            BindData_Category(0);
        }

        public void BindData_Category(int consumablePara)
        {
            DSItem.CategoryDataTable table = new DSItem.CategoryDataTable();
            table = adpCate.GetDataByConsumable(consumablePara);
            this.cbbCategory.DataSource = table;
            this.cbbCategory.DisplayMember = table.CategoryNameColumn.ColumnName;
            this.cbbCategory.ValueMember = table.CategoryIDColumn.ColumnName;
        }
        private void btnSearchOffice_Click(object sender, EventArgs e)
        {
            try
            {
                BindData_DGV();
                int itmeCount = this.dgvData.Rows.Count;
            }
            catch(Exception)
            {
                throw;
            }
        }

        public void BindData_DGV()
        {
            string itemID = this.txtItemID.Text.Trim();
            string itemName = this.txtName.Text.Trim();
            int category = Convert.ToInt32(this.cbbCategory.SelectedValue.ToString());
            string brand = this.txtBrand.Text.Trim();
            string model = this.txtModel.Text.Trim();
            DSItem.vw_ItemAndItemDetailDataTable table = new DSItem.vw_ItemAndItemDetailDataTable();
            table = adpItem.GetData(itemID, itemName, category, brand, model, statusID);
            table.Columns.Remove(table.CategoryIDColumn.ColumnName);
            if (consumable == 0)
            {
                table.Columns.Remove(table.QuantityColumn.ColumnName);
            }
            table.Columns.Remove(table.StatusIDColumn.ColumnName);
            table.Columns.Remove(table.DeviceStatusIDColumn.ColumnName);
            this.dgvData.DataSource = table;
        }
    }   
}
